import { ref, reactive } from 'vue'
import { testCaseDownload } from '@/api/test/test'
import { getFileType,getDownFile } from '@/utils/index'
import useInstance from "@/hooks/useInstance";

// 开启弹框 获取数据
export default function showModel() {
  // 借用数据 获取
  const { global } = useInstance();

  const RefShowFile = ref<{ show: (type: string, row?: any) => void }>();
  const isComponentLoaded = ref(false);
  const fileType = ref()
  const showBtn = (row) => {
    RefShowFile.value?.show('add', row)
  }
  const downLoadBtn = async (row) => {
    fileType.value = getFileType(row.fileName)

    const url = `/testCase/download?fileName=${row.fileName}&path=${row.path}`
    const res = await testCaseDownload(url)
    if (res) {
      getDownFile(res,row.fileName)
    } else {
      global.$message({ message: "下载失败", type: "error" });

    }
  }
  return {
    showBtn, RefShowFile, isComponentLoaded, downLoadBtn
  }
}
